package com.dao;

import com.domain.Bidding;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BiddingDao {

    /**
     * 公司竞单
     * @param bidding
     */
    @Insert("insert into bidding (order_id, estimated_price, start_time, finished_time, create_time, company_id, bidding_description) values " +
            "(#{order_id}, #{estimated_price}, #{start_time}, #{finished_time}, #{create_time}, #{company_id}, #{bidding_description})")
    public void addBidding(Bidding bidding);

    /**
     * 根据维修单查看所有竞单
     * @param id 维修单id
     * @return
     */
    @Select("select bidding.*, user.name as maintenance_company_name " +
            "from bidding, user " +
            "where bidding.order_id = #{id} and bidding.company_id = user.id")
    public List<Bidding> findAllByOrder(Integer id);

    /**
     * 修改竞单
     * @param bidding
     */
    @Update("update bidding set estimated_price = #{estimated_price}, start_time = #{start_time}, finished_time = #{finished_time}, bidding_description = #{bidding_description} " +
            "where order_id = #{order_id} and company_id = #{company_id}")
    public void updateBidding(Bidding bidding);

    /**
     * 根据维修单和公司查询竞单信息
     * @param order_id
     * @param company_id
     * @return
     */
    @Select("select bidding.*, user.name as maintenance_company_name " +
            "from bidding, user " +
            "where bidding.order_id = #{order_id} and bidding.company_id = user.id and " +
            "bidding.company_id = #{company_id}")
    public Bidding findBiddingByCompany(@Param("order_id") Integer order_id, @Param("company_id") Integer company_id);

    /**
     * 取消竞单
     * @param maintenance_company_id
     */
    @Delete("delete from bidding where company_id = #{maintenance_company_id} and order_id = #{id}")
    public void delByCompany(@Param("id") Integer id, @Param("maintenance_company_id") Integer maintenance_company_id);


}
